
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from './components/App.vue';
import "./assets/css/base.css"
const app = createApp(App).use(createPinia())

app.directive('focus', {
  mounted(el) {
    el.focus();
  }
});
let debounce = (fn, delay=100) => {
  var timer;
  return function() {
    var th = this;
    var args = arguments;
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(function() {
      timer = null;
      fn.apply(th, args);
    }, delay);
  };
}


app.directive('enterNumber', {
  mounted(el, { value = 100 }, vnode) {
    el = el.nodeName === "INPUT" ? el : el.children[0]
    var RegStr = value == 0 ? `^[\\+\\-]?\\d+\\d{0,0}` : `^[\\+\\-]?\\d+\\.?\\d{0,${value}}`;
    el.addEventListener('input', debounce(() => {
      el.value = el.value.match(new RegExp(RegStr, 'g'));
      el.dispatchEvent(new Event('input'))
    }));
  }
});
app.mount('#app');
